<template>
  <div class="pingfen">
    <!-- 表格 -->
    <div class="tableBox">
      <el-table :data="tableData" border style="width: 100%" :header-cell-style="{ textAlign: 'center',height: '60px' }" :cell-style="{ textAlign: 'center' }">
        <el-table-column prop="ruleProject" label="考核项目" width="400"></el-table-column>
        <el-table-column prop="score" label="得分/分" width="300">
          <template slot-scope="scope">
            <el-input @input="change()" v-model="scope.row.score" oninput ="value=value.replace(/[^\d]/g,'')"></el-input>
          </template>
        </el-table-column>
      </el-table>
      <el-table :data="tableDatab" :show-header='header' border  header-row-class-name="tableHead" style="width: 100%" :header-cell-style="{ textAlign: 'center',height: '60px' }" :cell-style="{ textAlign: 'center' }"> -->
        <el-table-column prop="project" label="考核项目" width="400"></el-table-column>
        <el-table-column prop="score" label="得分/分" width="300">
          <template slot-scope="scope">
            <el-input @input="change()" v-model="scope.row.score" maxlength="2" oninput ="value=value.replace(/[^\d]/g,'')" :disabled="scope.$index == (tableDatab.length - 1)" size="mini"></el-input>
          </template>
        </el-table-column>
      </el-table> 
      <div class="buttonBox">
        <button @click="submit()">提交审核</button>
      </div>
      <div class="remark">
        <p>备注：<br/>
            1、总分100分，由风控部与储运中心共同评分，达60分及以上可列入准入名单。<br/>
            2、偿债能力指标和盈利能力指标的评价来源于《企业绩效评价标准值》——运输业行业指标（国务院国资委考核分配局编制）</p>
      </div>
    </div>
  </div>
</template>


<script>
import {insertAscore,insertScoreListA} from '@/request/api'
export default {
  name: 'router.',
  data() {
    return {
      header:false,
      lastinput:false,
      totalscore:'',
      tableData:[],
      tableDatab:[
        // {project: '运输效率'},
        // {project: '运输安全'},
        // {project: '服务质量'},
        // {project: '客户满意度'},
        {project: '总分',score:this.totalscore},
      ],
    }
  },
  mounted(){
    this.listData()
  },
  methods:{
    listData(){
      insertScoreListA().then(res=>{
        this.tableData = res.data
      })
    },

    change(){
      let newArr = []
      let scoreArr = []
      this.tableDatab.forEach((items,index) => {
        if(index<this.tableDatab.length-1){
        if(items.score) {
          scoreArr.push(items.score)
        }else {
          newArr.push(items)
        }
        }
      })
      let numAarr = 0
      scoreArr.forEach(val => {
        numAarr += Number(val)
        this.tableDatab[this.tableDatab.length -1].score = String(numAarr)
      })
      this.totalscore=this.tableDatab[this.tableDatab.length -1].score
    },
    submit(){
      let newArr = []
      let scoreArr = []
      this.tableDatab.forEach(items => {
        if(items.score) {
          scoreArr.push(items.score)
        }else {
          newArr.push(items)
        }
      })
      var allscore= this.tableDatab[this.tableDatab.length -1].score
       if(newArr.length > 0) {
        this.$message({
            type:"error",
            message:"请输入分数"
          })
        return
      }
      if(allscore > 100){
        this.$message({
                    type:"error",
                    message:"满分100分"
                  })
        return
      }
      console.log(scoreArr)
      insertAscore({score: scoreArr}).then(res => {
        if(res.success=="1"){
          this.$message({
            type:"success",
            message:"提交成功"
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scope>
.pingfen {
  .tableBox {
    padding: 10px 20px;
    .buttonBox{
      height: 100px;
      line-height: 100px;
      text-align: center;
      button{
        width: 150px;
        height: 45px;
        background-color: #169BD5;
        cursor: pointer;
        color: #fff;
        font-size: 20px;
      }
    }
    .remark{
      p{
        font-size: 15px;
      }
    }
  }
}
.tableHead{
  font-size: 18px;
  letter-spacing:3px
}
</style>
